//部分控制器
var app = angular.module('myApp.controllers');

//example首页
app.controller('nearbyPark', ["$scope", "utilService", "$rootScope", "$ionicScrollDelegate", function ($scope, utilService, $rootScope, $ionicScrollDelegate) {

// 列表
    $scope.nearbyList = [
        {},
        {},
        {},
        {},
        {},
        {},
        {},
        {},
        {},
        {},
        {},
        {},
        {},
        {},
    ]
    $scope.contTop = {
        'top': '351px'
    }
    // 监听滚动
    var contScroll;
    utilService.$timeout(function() {
        contScroll = $ionicScrollDelegate.$getByHandle('mainScroll');
    });
    $scope.toThere = function () {
        console.log(1)
    }

    $scope.showList = true; //是否显示列表
    $scope.showMap = true; //是否显示地图

    // 下拉切换到地图模式
    $scope.toMap = function () {
        console.log('出发了')
        $scope.showList = false;
        $scope.showMap = true;
        $scope.$broadcast('scroll.refreshComplete');
        if(!$scope.$$phase) {
            $scope.$apply();
        }
    }

    // 滚动事件
    $scope.isScroll = function () {
        var top = contScroll.getScrollPosition().top;

        // 滚动到300px 隐藏地图 显示头部
        if (top >= 300) {
            $scope.contTop = {
                'top': '88px'
            }

            $scope.showMap = false;
            $scope.showList = true;
        }
    }
    // 切换至列表和地图都有的状态
    $scope.toList = function () {
        $scope.showMap = true;
        $scope.showList = true;
        contScroll.scrollTop(true);
        $scope.contTop = {
            'top': '351px'
        }
    }

    $scope.areaList = [
        {id:'1', name:'全部范围'},
        {id:'2', name:'1000米以内'},
        {id:'3', name:'2000米以内'},
        {id:'4', name:'5000米以内'}

    ]
    $scope.typeList = [
        {id:'1', name:'全部类型'},
        {id:'2', name:'地下停车场'},
        {id:'2', name:'地面停车场'},
        {id:'2', name:'路面停车场'}
    ]
    // 展示地址选择
    $scope.areaModal = false;
    $scope.typeModal = false;
    $scope.showAreaModal = function () {
        $scope.areaModal = !$scope.areaModal;
        $scope.typeModal = false;
    }
    $scope.showTypeModal = function () {
        $scope.typeModal = !$scope.typeModal;
        $scope.areaModal = false;
    }
    $scope.closeModal = function () {
        $scope.areaModal = false;
        $scope.typeModal = false;
    }
    $scope.$on('$ionicView.beforeEnter', function () {
        //页面刚加载
        utilService.$ionicLoading.show(HX_CONFIG.loadingBase);
    }, false);
    $scope.$on('$ionicView.afterEnter', function () {
        utilService.$rootScope.rootData.title = '车主服务';
        //页面加载完成
        utilService.$ionicLoading.hide();
    }, false);
    $rootScope.$on('$ionicView.beforeLeave', function (e, ion) {
        //页面离开之前
        //alertPopup && alertPopup.close();

    }, false);

}]);
//example首页
app.controller('nearbyFilling', ["$scope", "utilService", "$rootScope", "$ionicScrollDelegate", function ($scope, utilService, $rootScope, $ionicScrollDelegate) {

// 列表
    $scope.nearbyList = [
        {},
        {},
        {},
        {},
        {},
        {},
        {},
        {},
        {},
        {},
        {},
        {},
        {},
        {},
    ]
    $scope.contTop = {
        'top': '351px'
    }
    // 是否显示LIst
    var contScroll;
    utilService.$timeout(function() {
        contScroll = $ionicScrollDelegate.$getByHandle('mainScroll');
    });
    $scope.toThere = function () {
        console.log(1)
    }

    $scope.showList = true; //是否显示列表
    $scope.showMap = true; //是否显示地图

    // 下拉切换到地图模式
    $scope.toMap = function () {
        console.log('出发了')
        $scope.showList = false;
        $scope.showMap = true;
        $scope.$broadcast('scroll.refreshComplete');
        if(!$scope.$$phase) {
            $scope.$apply();
        }
    }

    // 滚动事件
    $scope.isScroll = function () {
        var top = contScroll.getScrollPosition().top;

        // 滚动到300px 隐藏地图 显示头部
        if (top >= 300) {
            $scope.contTop = {
                'top': '88px'
            }

            $scope.showMap = false;
            $scope.showList = true;
        }
    }
    // 切换至列表和地图都有的状态
    $scope.toList = function () {
        $scope.showMap = true;
        $scope.showList = true;
        contScroll.scrollTop(true);
        $scope.contTop = {
            'top': '351px'
        }
    }

    $scope.areaList = [
        {id:'1', name:'全部范围'},
        {id:'2', name:'1000米以内'},
        {id:'3', name:'2000米以内'},
        {id:'4', name:'5000米以内'}

    ]
    $scope.typeList = [
        {id:'1', name:'全部类型'},
        {id:'2', name:'地下停车场'},
        {id:'2', name:'地面停车场'},
        {id:'2', name:'路面停车场'}
    ]
    // 展示地址选择
    $scope.areaModal = false;
    $scope.typeModal = false;
    $scope.showAreaModal = function () {
        $scope.areaModal = !$scope.areaModal;
        $scope.typeModal = false;
    }
    $scope.showTypeModal = function () {
        $scope.typeModal = !$scope.typeModal;
        $scope.areaModal = false;
    }
    $scope.closeModal = function () {
        $scope.areaModal = false;
        $scope.typeModal = false;
    }
    $scope.$on('$ionicView.beforeEnter', function () {
        //页面刚加载
        utilService.$ionicLoading.show(HX_CONFIG.loadingBase);
    }, false);
    $scope.$on('$ionicView.afterEnter', function () {
        utilService.$rootScope.rootData.title = '车主服务';
        //页面加载完成
        utilService.$ionicLoading.hide();
    }, false);
    $rootScope.$on('$ionicView.beforeLeave', function (e, ion) {
        //页面离开之前
        //alertPopup && alertPopup.close();

    }, false);

}]);
//example首页
app.controller('nearbyUpkeep', ["$scope", "utilService", "$rootScope", "$ionicScrollDelegate", function ($scope, utilService, $rootScope, $ionicScrollDelegate) {

    $scope.shopList = [
        {},
        {},
    ]
    $scope.submitData = {
        keyword:''
    }

    $scope.areList = [
        {id:'1', name:'重庆市'},
        {id:'2', name:'江北区'},
        {id:'3', name:'沙坪坝区'},
        {id:'4', name:'大渡口区'},
        {id:'5', name:'南岸区'},
        {id:'6', name:'其他区'},
        {id:'7', name:'举个例子的'},

    ]
    $scope.typeList = [
        {id:'1', name:'距离优先'},
        {id:'2', name:'好评优先'}
    ]
    // 展示地址选择
    $scope.areaModal = false;
    $scope.typeModal = false;
    $scope.showAreaModal = function () {
        $scope.areaModal = !$scope.areaModal;
        $scope.typeModal = false;
    }
    $scope.showTypeModal = function () {
        $scope.typeModal = !$scope.typeModal;
        $scope.areaModal = false;
    }
    $scope.closeModal = function () {
        $scope.areaModal = false;
        $scope.typeModal = false;
    }
    $scope.$on('$ionicView.beforeEnter', function () {
        //页面刚加载

        var bannerH = angular.element(document.querySelector('#banner'))[0].offsetHeight;
        $scope.contTop = {
            'top': bannerH + 88 + 'px'
        };
        utilService.$ionicLoading.show(HX_CONFIG.loadingBase);
    }, false);
    $scope.$on('$ionicView.afterEnter', function () {

        utilService.$rootScope.rootData.title = '车主服务';
        //页面加载完成
        utilService.$ionicLoading.hide();
    }, false);
    $rootScope.$on('$ionicView.beforeLeave', function (e, ion) {
        //页面离开之前
        //alertPopup && alertPopup.close();

    }, false);

}]);
//example首页
app.controller('nearbyMaintain', ["$scope", "utilService", "$rootScope", "$ionicScrollDelegate", function ($scope, utilService, $rootScope, $ionicScrollDelegate) {
    $scope.shopList = [
        {},
        {},
    ]
    $scope.submitData = {
        keyword:''
    }

    $scope.areList = [
        {id:'1', name:'重庆市'},
        {id:'2', name:'江北区'},
        {id:'3', name:'沙坪坝区'},
        {id:'4', name:'大渡口区'},
        {id:'5', name:'南岸区'},
        {id:'6', name:'其他区'},
        {id:'7', name:'举个例子的'},

    ]
    $scope.typeList = [
        {id:'1', name:'距离优先'},
        {id:'2', name:'好评优先'}
    ]
    // 展示地址选择
    $scope.areaModal = false;
    $scope.typeModal = false;
    $scope.showAreaModal = function () {
        $scope.areaModal = !$scope.areaModal;
        $scope.typeModal = false;
    }
    $scope.showTypeModal = function () {
        $scope.typeModal = !$scope.typeModal;
        $scope.areaModal = false;
    }
    $scope.closeModal = function () {
        $scope.areaModal = false;
        $scope.typeModal = false;
    }

    $scope.$on('$ionicView.beforeEnter', function () {
        //页面刚加载
        var bannerH = angular.element(document.querySelector('#banner'))[0].offsetHeight;
        $scope.contTop = {
            'top': bannerH + 88 + 'px'
        };

        utilService.$ionicLoading.show(HX_CONFIG.loadingBase);
    }, false);
    $scope.$on('$ionicView.afterEnter', function () {
        utilService.$rootScope.rootData.title = '车主服务';
        //页面加载完成
        utilService.$ionicLoading.hide();
    }, false);
    $rootScope.$on('$ionicView.beforeLeave', function (e, ion) {
        //页面离开之前
        //alertPopup && alertPopup.close();

    }, false);

}]);
//example首页
app.controller('nearbyWash', ["$scope", "utilService", "$rootScope", "$ionicScrollDelegate", function ($scope, utilService, $rootScope, $ionicScrollDelegate) {


    $scope.shopList = [
        {},
        {},
    ]

    $scope.areList = [
        {id:'1', name:'重庆市'},
        {id:'2', name:'江北区'},
        {id:'3', name:'沙坪坝区'},
        {id:'4', name:'大渡口区'},
        {id:'5', name:'南岸区'},
        {id:'6', name:'其他区'},
        {id:'7', name:'举个例子的'},

    ]
    $scope.sortList = [
        {id:'1', name:'普洗(5座)'},
        {id:'1', name:'普洗(7座)'},
        {id:'1', name:'精洗(5座)'},
        {id:'1', name:'精洗(7座)'}
    ]
    $scope.typeList = [
        {id:'1', name:'距离优先'},
        {id:'2', name:'好评优先'}
    ]
    // 展示地址选择
    $scope.areaModal = false;
    $scope.typeModal = false;
    $scope.sortModal = false;
    $scope.showAreaModal = function () {
        $scope.areaModal = !$scope.areaModal;
        $scope.typeModal = false;
        $scope.sortModal = false;
    }
    $scope.showTypeModal = function () {
        $scope.typeModal = !$scope.typeModal;
        $scope.areaModal = false;
        $scope.sortModal = false;
    }
    $scope.showSortModal = function () {
        $scope.sortModal = !$scope.sortModal;
        $scope.areaModal = false;
        $scope.typeModal = false;
    }
    $scope.closeModal = function () {
        $scope.areaModal = false;
        $scope.typeModal = false;
        $scope.sortModal = false;
    }

    $scope.$on('$ionicView.beforeEnter', function () {
        //页面刚加载
        // utilService.$timeout(function () {
            var bannerH = angular.element(document.querySelector('#banner'))[0].offsetHeight;
            $scope.contTop = {
                'top': bannerH + 88 + 'px'
            };
        // },20)

        utilService.$ionicLoading.show(HX_CONFIG.loadingBase);
    }, false);
    $scope.$on('$ionicView.afterEnter', function () {

        utilService.$rootScope.rootData.title = '车主服务';
        //页面加载完成
        utilService.$ionicLoading.hide();
    }, false);
    $rootScope.$on('$ionicView.beforeLeave', function (e, ion) {
        //页面离开之前
        //alertPopup && alertPopup.close();

    }, false);

}]);